let app = getApp();
let page_s = 1; // 当前页
let pagesize = 10; // total
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    // 是否隐藏
    isShow: {
      type: Boolean,
      value: false
    },
    // 已选中ID
    bankno_id: {
      type: Number,
      value: null,
    },
    bankno_name: {
      type: String,
      value: '',
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    datalist:[],
    checkId:null,//确认选择时id
    checkName:'', //确认选择的列表
    checkItem:{},//选中的门店
    loadingState: '',//loading 加载中  nomore 没有更多 more 上划加载 allLoading 关闭加载
    searchValue:'',
    triggered: false,//下拉加载
  },
  //数据变化监听
  observers: {
    'isShow': function (value) {
      if (value) {
        let id = this.properties.bankno_id;
        let name = this.properties.bankno_name;
        this.setData({
          checkId:id,
          checkName:name
        })
        this.onRefresh()  
      }
    }
  },
  lifetimes: {
    attached: function() {
    },
    detached: function() {
      // 在组件实例被从页面节点树移除时执行
    },
  },
  /**
   * 组件的方法列表
   */
  methods: {
    /**
     * 页面上拉触底事件的处理函数
     */
    onTolower(e){
      if (this.data.loadingState == 'more'){
        page_s += 1;
        this.getList();
      }
    },
    onRefresh() {
      this.setData({
        triggered:true
      })
      this.intData()
      this.getList()
    },
    intData(){
      page_s = 1;
      this.setData({
        datalist: [],
      })
    },
    searchFun(e){
      let value = e.detail.value
      let obj = e.currentTarget.dataset.obj
      this.setData({
        [`${obj}`]: value
      });
      this.intData()
      this.getList()
    },
    //获取数据列表 
    getList() {
      // return false
      let loadingState = this.data.datalist.length ? 'loading' : 'allLoading'
      this.setData({
        loadingState,
      })
      let searchValue = this.data.searchValue
      let formData = {
        page: page_s,
				pageSize: pagesize,
        keywords:searchValue,
        bank_name:''
      };
      app.ajax({
        url: 'User/Withdraw/getBankNo',
        method: "POST",
        data: formData,
        success: (res) => {
          console.log('看哈',res)
          // return false
          if (res.data.code == 1000) {
            let datalist = page_s == 1 ? [] : this.data.datalist
            let data = res.data.data.data
            datalist.push(...data)
            loadingState = res.data.data.nowPage < res.data.data.allPage ? 'more' : 'nomore'
            this.setData({
              datalist,
              loadingState
            })
            console.log('列表',datalist,data)
            // return false
          } else {
            app.showToast(res.msg, "none", 2000, function () {});
          }
          this.setData({
            triggered:false
          })
        },
        fail: (err) => {
          console.log('getListindex error', err);
        }
      })
    },
    hidePopup() {
      //初始化组件值 并关闭
      this.setData({
        isShow: false
      })
    },
    //确认选择 并赋值给父组件 初始化当前组件模糊查询
    clinchBtn() {
      let id = this.data.checkId
      let name = this.data.checkName
      let item = this.data.checkItem
      console.log('确认操作',id,name)
      // return false
      this.triggerEvent('clinchChecked', { id,name,item });
      this.hidePopup()
      //调用父组件方法
    },
    //选择门店
    changeItem(e){
      let self = this
      let {item} = e.currentTarget.dataset;
      this.setData({
        checkId:item.bank_no,
        checkName:item.bank_name,
        checkItem:item
      })
      console.log('什么意思',this.data.checkItem)
    },
    
    // 在methods里面声明一个函数放着就行
		moveHandle(){},
  }
});
